﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Globalization;
using System.Net;

namespace Browis.Utils
{
    public static class HttpWebRequestEx
    {
        public static void AddRange(this HttpWebRequest request, long from, long to)
        {
            BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
            Type type = request.GetType();
            MethodInfo method = type.GetMethod("AddRange", flag);
            object[] param = new object[] { "bytes", from.ToString(NumberFormatInfo.InvariantInfo), to.ToString(NumberFormatInfo.InvariantInfo) };
            method.Invoke(request, param);
        }

        public static void AddRange(this HttpWebRequest request, long from)
        {
            BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic;
            Type type = request.GetType();
            MethodInfo method = type.GetMethod("AddRange", flag);
            object[] param = new object[] { "bytes", from.ToString(NumberFormatInfo.InvariantInfo), (from >= 0) ? "" : null };
            method.Invoke(request, param);
        }

    }
}
